home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / SEARCH.C < prev    next >
Text File  |  1990-11-09  |  6KB  |  229 lines

  1. /* Performs search for matching msgs */
  2.  
  3.  
  4. #include "msgg.h"
  5. #include "twindow.h"
  6. #include "keys.h"
  7. #include "headedit.h"
  8.  
  9. extern WINDOW *ewnd;
  10.  
  11.  
  12. word pascal search (char type,char reverse) {
  13.  
  14.     static char from[36]="";
  15.     static char to[36]="";
  16.     static char subj[64]="";
  17.     static char text[79]="";
  18.     static char text2[79]="";
  19.     static char text3[79]="";
  20.     static char text4[79]="";
  21.     char *textptr;
  22.     static char exclude[2]="-";
  23.     static char tome[2]="-";
  24.     static char orit[2]="-";
  25.     static char direction[2]="-";
  26.     char compare[64];
  27.     char *p;
  28.     char far *hold;
  29.     int returncode;
  30.     word tempmess;
  31.     char got=0;
  32.     char miss=0;
  33.     WINDOW *wnd=NULL;
  34.     FIELD *fld;
  35.  
  36.     if (nomess<=1) return 0;
  37.     tempmess=messno;
  38.     if (!*from && !*to && !*subj && !*text && *tome!='X' && !*text2 && !*text3 && !*text4) type=0;
  39.     if (!type) {
  40.         wnd=establish_window(1,maxy-11,18,80);
  41.         set_border(wnd,1);
  42.         set_title(wnd," Message Search Criteria ");
  43.         set_colors(wnd,BORDER,7,0,0);
  44.         display_window(wnd);
  45.         wcursor(wnd,0,0);
  46.         wprintf(wnd," ESC to save, F10 to save & search");
  47.         init_template(wnd);
  48.         wprompt(wnd,1,2,"From:");
  49.         wprompt(wnd,1,3,"To:");
  50.         wprompt(wnd,1,4,"Subj:");
  51.         wprompt(wnd,1,5,"Message body text:");
  52.         wprompt(wnd,1,7,"Exclude:  [ ]");
  53.         wprompt(wnd,1,8,"Personal: [ ]");
  54.         wprompt(wnd,1,9,"Match any:[ ]");
  55.         wprompt(wnd,18,9,"Backwards: [ ]");
  56.         wprompt(wnd,1,10,"Additional body text:");
  57.         wprompt(wnd,1,12,"Additional body text:");
  58.         wprompt(wnd,1,14,"Additional body text:");
  59.         fld=establish_field(wnd,7,2,msk35,from,'A');
  60.         field_window(fld,"findfrom  ",40,4);
  61.         fld=establish_field(wnd,7,3,msk35,to,'A');
  62.         field_window(fld,"findto    ",40,4);
  63.         fld=establish_field(wnd,7,4,msk63,subj,'A');
  64.         field_window(fld,"findsubj  ",40,5);
  65.         fld=establish_field(wnd,1,6,msk78,text,'A');
  66.         field_window(fld,"bodytext  ",40,5);
  67.         fld=establish_field(wnd,12,7,msk1,exclude,'O');
  68.         field_window(fld,"exclude   ",40,6);
  69.         fld=establish_field(wnd,12,8,msk1,tome,'O');
  70.         field_window(fld,"tome      ",40,6);
  71.         fld=establish_field(wnd,12,9,msk1,orit,'O');
  72.         field_window(fld,"matchany  ",40,6);
  73.         fld=establish_field(wnd,30,9,msk1,direction,'O');
  74.         field_window(fld,"backward  ",40,6);
  75.         fld=establish_field(wnd,1,11,msk78,text2,'A');
  76.         field_window(fld,"bodytext  ",40,7);
  77.         fld=establish_field(wnd,1,13,msk78,text3,'A');
  78.         field_window(fld,"bodytext  ",40,7);
  79.         fld=establish_field(wnd,1,15,msk78,text4,'A');
  80.         field_window(fld,"bodytext  ",40,7);
  81.         prep_template(wnd);
  82. Over:
  83.         returncode=data_entry(wnd);
  84.         if (returncode!=F10 && returncode!=ESC) goto Over;
  85.         if (returncode==ESC) {
  86.             rstrip(from);
  87.             rstrip(to);
  88.             rstrip(subj);
  89.             rstrip(text);
  90.             rstrip(text2);
  91.             rstrip(text3);
  92.             rstrip(text4);
  93.             clear_message();
  94.             delete_window(wnd);
  95.             return messno;
  96.         }
  97.     }
  98.     else if (reverse) {
  99.         if(*direction=='X') *direction='-';
  100.         else *direction='X';
  101.     }
  102.     clear_message();
  103.     if(wnd)delete_window(wnd);
  104.     rstrip(from);
  105.     rstrip(to);
  106.     rstrip(subj);
  107.     rstrip(text);
  108.     rstrip(text2);
  109.     rstrip(text3);
  110.     rstrip(text4);
  111.     if(*direction!='X')messno++;
  112.     else messno--;
  113.     if(messno>nomess) messno=1;
  114.     while (messno>0 && messno<nomess+1) {
  115.          if (!ewnd) any_message(" Searching:        ");
  116.          wcursor(ewnd,12,0);
  117.          wprintf(ewnd,"%-5u",messno);
  118.          if (kbhit()) {
  119.             returncode=get_char();
  120.             if (returncode==' ' || returncode==ESC) break;
  121.          }
  122.          get_mess(1);
  123.          if (*tome=='X') {
  124.             if (*exclude=='X') {
  125.                 if (isitme(1)) {
  126.                     miss++;
  127.                     if(*orit!='X') goto IncIt;
  128.                 }
  129.                 else {
  130.                     got++;
  131.                     if(*orit=='X') goto ThisOne;
  132.                 }
  133.             }
  134.             else {
  135.                 if (!isitme(1)) {
  136.                     miss++;
  137.                     if(*orit!='X') goto IncIt;
  138.                 }
  139.                 else {
  140.                     got++;
  141.                     if(*orit=='X') goto ThisOne;
  142.                 }
  143.             }
  144.          }
  145.          if (*to) {
  146.              if ((*exclude=='X')==(stricmp(msg2.to,to)==0)) {
  147.                 miss++;
  148.                 if(*orit!='X') goto IncIt;
  149.              }
  150.              else {
  151.                 got++;
  152.                 if(*orit=='X')goto ThisOne;
  153.              }
  154.          }
  155.          if (*from) {
  156.              if ((*exclude=='X')==(stricmp(msg2.from,from)==0)) {
  157.                 miss++;
  158.                 if(*orit!='X') goto IncIt;
  159.              }
  160.              else {
  161.                 got++;
  162.                 if(*orit=='X')goto ThisOne;
  163.              }
  164.          }
  165.          if (*subj) {
  166.              strcpy(compare,msg2.subj);
  167.              if (!strnicmp(compare,"RE: ",4)) {
  168.                 strcpy(compare,&msg2.subj[4]);
  169.              }
  170.              rstrip(compare);
  171.              if ((*exclude!='X')==(stristr(compare,subj)==NULL)) {
  172.                 miss++;
  173.                 if(*orit!='X')goto IncIt;
  174.              }
  175.              else {
  176.                 got++;
  177.                 if(*orit=='X')goto ThisOne;
  178.              }
  179.          }
  180.          textptr=text;
  181.          hold=NULL;
  182.          if(*text || *text2 || *text3 || *text4) {
  183.             get_mess(0);
  184.             hold=get_text();
  185.             if (!*hold || hold==NULL) goto IncIt;
  186. TextLoop:
  187.             if (*textptr) {
  188.                 p=stristr(hold,textptr);
  189.                 if (((*exclude!='X') && (p==NULL)) || ((*exclude=='X') && (p!=NULL))) {
  190.                     miss++;
  191.                     if(*orit!='X') {
  192.                         if(hold)free(hold);
  193.                         goto IncIt;
  194.                     }
  195.                 }
  196.                 else got++;
  197.              }
  198.              if(textptr==text) {
  199.                 textptr=text2;
  200.                 if(*textptr)goto TextLoop;
  201.              }
  202.              if(textptr==text2) {
  203.                 textptr=text3;
  204.                 if(*textptr)goto TextLoop;
  205.              }
  206.              if(textptr==text3) {
  207.                 textptr=text4;
  208.                 if(*textptr)goto TextLoop;
  209.              }
  210.              if(hold)free(hold);
  211.          }
  212.  
  213.          if((*orit!='X' && miss) || !got) goto IncIt;
  214. ThisOne:
  215.          clear_message();
  216.          return messno;
  217. IncIt:
  218.          got=miss=0;
  219.          if(*direction!='X')messno++;
  220.          else messno--;
  221.     }
  222.     any_message("Complete.");
  223.     nopause();
  224.     messno=tempmess;
  225.     get_mess(0);
  226.     return messno;
  227. }
  228.  
  229.